<template>
	<el-dialog :title="dialogTitle" :visible.sync="visible" width="560px" top="0" append-to-body>
		<el-form v-bind="formConfig" :model="formData" :rules="formRules" label-width="80px">
			<el-row :gutter="24">
				<el-col :span="24">
					<el-form-item label="字典名称" prop="content">
						<el-input v-model="formData.content"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="13">
					<el-form-item label="字典编码" prop="code">
						<sw-custom-input type="capital" v-model="formData.code" placeholder="请输入字典编码" :disabled="!addOrEdit" />
					</el-form-item>
				</el-col>
				<el-col :span="11">
					<el-form-item label="字典类型" prop="type">
						<el-radio-group v-model="formData.type" :disabled="!addOrEdit">
							<el-radio label="1">枚举</el-radio>
							<el-radio label="2">常量</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="字典描述">
						<el-input type="textarea" v-model="formData.name"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template slot="footer">
			<el-button size="medium" @click="visible = false">取消</el-button>
			<el-button size="medium" type="primary" :loading="btnLoading" @click="handleSubmitForm">确定</el-button>
		</template>
	</el-dialog>
</template>

<script>
import lodash from 'lodash';
import formMixins from '@/mixins/formMixins';
import { queryDictDefine, addedDictDefine, updateDictDefine } from '@/api/system/tbSysDictDefinition';
export default {
	mixins: [formMixins],
	props: {
		type: { type: String, default: '' }
	},
	data() {
		return {
			formName: '字典定义',
			formRules: {
				content: [{ required: true, message: '请输入字典名称', trigger: 'blur' }],
				code: [{ required: true, message: '请输入字典编码', trigger: 'blur' }],
				type: [{ required: true, message: '请选择字典类型', trigger: 'change' }]
			}
		};
	},
	computed: {
		detailData() {
			return eval(queryDictDefine);
		},
		callFunction() {
			return eval(this.addOrEdit ? addedDictDefine : updateDictDefine);
		},
		submitParams() {
			if (!this.addOrEdit) {
				return this.formData;
			} else {
				return {
					code: this.formData.code,
					content: this.formData.content,
					name: this.formData.name,
					type: this.formData.type,
					entity: this.formData
				};
			}
		}
	},
	methods: {
		formatFormParams() {
			if (!this.addOrEdit) return false;
			this.$set(this.formData, 'type', this.type);
		}
	}
};
</script>

<style lang="scss" scoped></style>
